<!doctype html>
<html lang="en">
<head>
    <?php require_once "include/header.php" ?>
    <script>
        function del(id) {
            if (confirm('are u sure?')) {
                window.location = 'blog/blog_action.php?action=del&id=' + id;
            }
        }
        $(document).ready(function () {
            $(document).bind("keyup", function (e) {
                console.log(e.keyCode);

                e.preventDefault();
                if (e.keyCode == 66) {//b
                    window.location = "blog/blog_new.php";
                } else if (e.keyCode == 84) {//t
                    window.location = "todo/todo_list.php";
                }
            })
        });
    </script>
</head>
<body>

<?php
require_once('include/conn.php');
$result = mysql_query("SELECT * FROM blog order by post_date desc");

if (!$result) {
    echo "db error:" . mysql_error() . "<br/>";
    echo "<section>
            Please <a href='setup.php'> setup database</a> first.<br/>
        </section>";
} else {
    ?>


    <table class="table">
        <caption>
            <a href="blog/blog_new.php">new blog</a>

        </caption>
        <tr>
            <th>title</th>
            <th>date</th>
            <th>&nbsp;</th>
        </tr>

        <?php
        while ($row = mysql_fetch_array($result)) {
            echo "<tr><td><a href='blog/blog_view.php?id=" . $row["id"] . "'>" . $row['title'] . "</a></td>";
            echo "<td>" . $row['post_date'] . "</td>";
            echo "<td><a href='javascript:del(" . $row["id"] . ")'>delete</a></td></tr>";
        }
        ?>

    </table>
    <div class="pager">
        <span> |&lt; </span>
        <a href=""><span> &lt;&lt; </span></a>
        <span> &gt;&gt;</span>
        <span> &gt;| </span>


        <div class="fr">
            go to <input type="number" name="pageIndex" id="pageIndex" max="99" size="2"/>
        </div>
    </div>
<?php
}
?>
</div>
</body>
</html>

<?php
mysql_close($conn);
?>